﻿@model IEnumerable<lsc.Model.UserRole>

@{
    ViewData["Title"] = "角色管理";
    Layout = "~/Pages/_Layout.cshtml";
}


<blockquote class="layui-elem-quote">
    本页面系统中所有用户角色
    <a class="layui-btn layui-btn-normal addrole" href="javascript:;" target="_blank" >添加角色</a>
</blockquote>

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>模块列表</legend>
</fieldset>
<table class="layui-table">
    <colgroup>
        <col width="120" />
        <col width="150" />
        <col width="60" />
    </colgroup>
    <thead>
        <tr>
            <th>角色ID</th>
            <th>角色名称</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody>
        @if (Model != null && Model.Count() > 0)
        {
            foreach (var m in Model)
            {
                <tr>
                    <td>@m.ID</td>
                    <td>@m.RoleName</td>
                    <td>
                        <button onclick="Del('@m.ID')" class="layui-btn layui-btn-small layui-btn-radius layui-btn-danger"><i class="layui-icon"></i>删除</button>
                        <a href="/Users/AddRoleJuri?roleid=@(m.ID)" class="layui-btn layui-btn-small layui-btn-normal"><i class="layui-icon">&#xe608;</i>分配权限</a>
                    </td>
                </tr>
            }
        }
    </tbody>
</table>

@section Scripts{
    <script type="text/javascript">
        var layer
        layui.use(['layer','element'], function () {
            var element = layui.element
            layer = layui.layer;
        })
        $(".addrole").on('click', function () {
            layer.prompt({ title: '请输角色名称：', formType: 3 }, function (text, index) {
                layer.close(index);
                $.post('/Users/AddRole', { name: text }, function (res) {
                    if (res.code === 1) {
                        window.location.reload()
                    }
                })
            });
        })
        function Del(id) {
            layer.confirm('是否删除该模块？', {
                btn: ['删除', '取消'] //按钮
            }, function () {
                $.get('/Users/DelRole?id=' + id, function (res) {
                    if (res.code === 1) {
                        layer.msg('删除成功', { icon: 6 });
                        window.location.reload()
                    } else {
                        layer.msg('删除失败', { icon: 5 });
                    }
                })
            }, function () {
            });
        }

    </script>
}